<script setup>
import { getHotGoodsAPI } from '@/apis/detail.js'
import { ref } from 'vue'
import GoodsItem from '@/components/GoodsItem.vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const props = defineProps({
  hotType: {
    type: Number,
  }
})

const goods = ref([])
const getHotGoods = async () => {
  const res = await getHotGoodsAPI({
    id: route.params.id,
    type: props.hotType,
    limit: 3
  })

  goods.value = res.data.result
}

getHotGoods()
</script>

<template>
  <div class="goods-hot">
    <h3>{{ props.hotType === 1 ? '二十四小时热榜' : '周热榜' }}</h3>
    <!-- 商品区块 -->
    <RouterLink
to="/"
class="goods-item"
v-for="item in goods"
:key="item.id"
>
      <GoodsItem :good="item"></GoodsItem>
    </RouterLink>
  </div>
</template>

<style scoped lang="scss">
.goods-hot {
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;

    img {
      width: 160px;
      height: 160px;
    }

    p {
      padding-top: 10px;
    }

    .name {
      font-size: 16px;
    }

    .desc {
      color: #999;
      height: 29px;
    }

    .price {
      color: $priceColor;
      font-size: 20px;
    }
  }
}
</style>
